/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.model.staff;

import br.gov.cemaden.library.model.BaseEntity;
import br.gov.cemaden.library.model.Usuario;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import org.hibernate.annotations.Type;

/**
 *
 * @author paulo.dias
 */
@Entity
@Table(name="stf_aplicacao", schema = "staff")    
@SequenceGenerator(name = "sequence", sequenceName = "staff.stf_aplicacao_sequence", schema = "staff")
@NamedQueries({
    @NamedQuery(name = "Aplicacao.findAll", query = "SELECT a FROM Aplicacao a ORDER BY a.id ASC"),
    @NamedQuery(name = "Aplicacao.findById", query = "SELECT a FROM Aplicacao a WHERE a.id = :id"),
    @NamedQuery(name = "Aplicacao.findByNome", query = "SELECT a FROM Aplicacao a WHERE a.nome = :nome"),
    @NamedQuery(name = "Aplicacao.findByTempo", query = "SELECT a FROM Aplicacao a WHERE a.tempo = :tempo"),
})
public class Aplicacao implements Serializable, BaseEntity{    
    @Id
    @GeneratedValue(generator = "sequence", strategy = GenerationType.AUTO)
    @Column(name="id_aplicacao", nullable = false, unique = true)    
    private Long id;
    
    @Column(name="nome", nullable = false)
    private String nome;
    
    @Column(name="descricao")
    private String descricao;
    
    @Column(name="max_sem_exec")
    private Integer tempo;
    
    @Lob
    @Type(type = "org.hibernate.type.TextType")
    @Column(name = "script")
    private String script;
    
    @Lob
    @Type(type = "org.hibernate.type.TextType")
    @Column(name = "mensagem")
    private String mensagem;
    
    @ManyToMany
    @JoinTable(name = "smp_usuario_aplic", schema = "smp", 
            joinColumns = {@JoinColumn(name = "id_aplicacao")},
            inverseJoinColumns = {@JoinColumn(name = "id_usuario")})
    private Set<Usuario> usuarios = new HashSet<Usuario>();
    
    public Aplicacao(){        
    }   
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }
    
    public String getNome() {
        return nome;
    }

    public void setNome(String nome) {
        this.nome = nome;
    }

    public String getDescricao() {
        return descricao;
    }

    public void setDescricao(String descricao) {
        this.descricao = descricao;
    }

    public Integer getTempo() {
        return tempo;
    }

    public void setTempo(Integer tempo) {
        this.tempo = tempo;
    }

    public String getScript() {
        return script;
    }

    public void setScript(String script) {
        this.script = script;
    }

    public String getMensagem() {
        return mensagem;
    }

    public void setMensagem(String mensagem) {
        this.mensagem = mensagem;
    }        

    public Set<Usuario> getUsuarios() {
        return usuarios;
    }

    public void setUsuarios(Set<Usuario> usuarios) {
        this.usuarios = usuarios;
    }        

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 37 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Aplicacao other = (Aplicacao) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Aplicacao{" + "id=" + id + ", nome=" + nome + ", descricao=" + descricao + ", tempo=" + tempo + '}';
    }       
  
}
